/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Negocio;

import DAO.AddAluno;
import DAO.AddAlunos;
import DAO.Data;
import gui.MWRibbon;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import org.jdesktop.swingx.JXBusyLabel;
import org.prevayler.Prevayler;
import org.prevayler.PrevaylerFactory;


/**
 *
 * @author jeferson
 */
public class Backup implements Runnable{
    
    private String dir;
    private JXBusyLabel bl;
    private Prevayler prev;
    private ArrayList<Aluno> alunos;
    private MWRibbon mwr;

    public Backup(String dir, JXBusyLabel bl, ArrayList<Aluno> alunos, MWRibbon mwr) {
        this.dir = dir;
        this.bl = bl;
        this.alunos = alunos;
        bl.setText("Fazendo Backup");
        this.mwr = mwr;
    }

    @Override
    public void run() {
        bl.setBusy(true);
        PrevaylerFactory factory = new PrevaylerFactory();
        factory.configurePrevalenceDirectory(dir);
        factory.configurePrevalentSystem(new Data());
        try {
            prev = factory.create();
            prev.execute(new AddAlunos(alunos));
            bl.setBusy(false);
            bl.setText("");
            JOptionPane.showMessageDialog(mwr, "Backup concluído com sucesso!");
        } catch (IOException ex) {
            Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(mwr, "Problema na criação do backup");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(mwr, "Problema na criação do backup");
        }
    }
    
}
